﻿using JiveMessenger.Utilities;
using JiveMessenger.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinampLib;

namespace JiveMessenger.User
{
    public class WinampHelper
    {
        public static Tuple<string,TrackInfo> GetNowPlayingText()
        {
            try
            {
                TrackInfo info = WinampApi.GetCurrentTrackInfo();
                string format = VmHelper.Locator.CurrentClient.UserSettings.NowPlayingFormat;
                string songtitle = info.Title != null ? info.Title.ToString() : "N/A";
                string albumTitle = info.Album != null ? info.Album.ToString() : "N/A";
                string artistName = info.Artist != null ? info.Artist.ToString() : "N/A";
                int durationInSeconds = (int)info.TrackLength / 1000;
                int positionInSeconds = (int)info.TrackPosition / 1000;
                format = format.Replace("{artist}", artistName);
                format = format.Replace("{title}", songtitle);
                format = format.Replace("{album}", albumTitle);
                format = format.Replace("{elapsed}", StaticMethods.TimeSpanToFormattedString(durationInSeconds));
                format = format.Replace("{duration}", StaticMethods.TimeSpanToFormattedString(positionInSeconds));
                format = format.Replace("{status}", info.PlaybackStatus.ToString());


                return new Tuple<string, TrackInfo>(format, info);
            }
            catch (Exception ex)
            {
                return new Tuple<string, TrackInfo>("N/A", null);
            }
        }
    }
}
